package com.shiku.imserver;

import com.shiku.imserver.common.ws.WsMsgHandler;
import com.shiku.imserver.common.ws.WsServerConfig;
import com.shiku.imserver.hander.ImServerHandler;
import com.shiku.imserver.hander.TcpServerHandler;
import com.shiku.imserver.hander.WsServerAioHandler;
import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.server.ServerGroupContext;
import org.tio.server.intf.ServerAioHandler;
import org.tio.server.intf.ServerAioListener;
import org.tio.utils.thread.pool.DefaultThreadFactory;
import org.tio.utils.thread.pool.SynThreadPoolExecutor;

public class ImServerGroupContext extends ServerGroupContext {
    private static int CORE_POOL_SIZE = (Runtime.getRuntime().availableProcessors() * 2);
    private Logger log;
    private ServerAioHandler tcpServerAioHandler;
    private ServerAioListener tcpServerAioListener;
    protected SynThreadPoolExecutor timExecutor;
    private ServerAioHandler wsServerAioHandler;
    private ServerAioListener wsServerAioListener;

    public ImServerGroupContext(ImServerHandler imServerAioHandler, ServerAioListener imServerAioListener) {
        super("Shiku IM Server", imServerAioHandler, imServerAioListener);
        this.log = LoggerFactory.getLogger(ImServerGroupContext.class);
        this.timExecutor = null;
        this.wsServerAioHandler = null;
        this.wsServerAioListener = null;
        this.tcpServerAioHandler = null;
        this.tcpServerAioListener = null;
        this.tcpServerAioHandler = new TcpServerHandler();
        this.wsServerAioHandler = new WsServerAioHandler(new WsServerConfig(5280, true), new WsMsgHandler());
        if (this.timExecutor == null) {
            this.timExecutor = new SynThreadPoolExecutor(CORE_POOL_SIZE, CORE_POOL_SIZE, 0, new LinkedBlockingQueue<>(), DefaultThreadFactory.getInstance("Shiku IM Server", 5), "Shiku IM Server");
            this.timExecutor.prestartAllCoreThreads();
        }
    }

    public SynThreadPoolExecutor getTimExecutor() {
        return this.timExecutor;
    }

    public ServerAioListener getWsServerAioListener() {
        return this.wsServerAioListener;
    }

    public void setWsServerAioListener(ServerAioListener wsServerAioListener2) {
        this.wsServerAioListener = wsServerAioListener2;
    }

    public ServerAioHandler getWsServerAioHandler() {
        return this.wsServerAioHandler;
    }

    public void setWsServerAioHandler(ServerAioHandler wsServerAioHandler2) {
        this.wsServerAioHandler = wsServerAioHandler2;
    }

    public ServerAioHandler getTcpServerAioHandler() {
        return this.tcpServerAioHandler;
    }

    public void setTcpServerAioHandler(ServerAioHandler tcpServerAioHandler2) {
        this.tcpServerAioHandler = tcpServerAioHandler2;
    }

    public ServerAioListener getTcpServerAioListener() {
        return this.tcpServerAioListener;
    }

    public void setTcpServerAioListener(ServerAioListener tcpServerAioListener2) {
        this.tcpServerAioListener = tcpServerAioListener2;
    }
}
